"""
    说明：
        在Selenium中将鼠标操作方法封装在ActionChains类中

    实例化对象：
        action = ActionChains(driver)

    方法：
        drag_and_drop(source, target)   拖动 --> 模拟鼠标拖动效果
"""
# 导包
from selenium import webdriver
from time import sleep

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

# 获取浏览器驱动对象
driver = webdriver.Chrome()

# 打开url
url = r"D:\python\python-selenium-learn\a03_元素和浏览器的操作方法\learn-files\drop.html"
driver.get(url)

# 实例化并获取 ActionChains 类
action = ActionChains(driver)

# 获取源元素
source = driver.find_element(By.CSS_SELECTOR, "#div1")
# 获取目标元素
target = driver.find_element(By.CSS_SELECTOR, "#div2")
sleep(2)
action.drag_and_drop(source, target).perform()

# 扩展：通过坐标偏移量执行
action.drag_and_drop_by_offset(source, xoffset=360, yoffset=180).perform()

# 暂停3秒
sleep(3)

# 关闭驱动对象
driver.quit()


